package org.ymjava.medical.db.AllPackage.biz;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.ymjava.medical.db.AbstractBaseBiz.BaseBiz;
import org.ymjava.medical.db.AllPackage.entity.NurseAdmin;
import org.ymjava.medical.db.AllPackage.mapper.NurseAdminMapper;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 管理员表
 *
 * @author zhy
 * @email ${email}
 * @date 2020-04-03 15:53:44
 */
@Service
public class NurseAdminBiz extends BaseBiz<NurseAdminMapper, NurseAdmin> {

	@Resource
	private NurseAdminMapper nurseAdminMapper;

	public Map<String, Object> querySelective(String username, Integer page, Integer limit, String sort, String order) {
		Example example = new Example(NurseAdmin.class);
		if (!StringUtils.isEmpty(username)) {
			example.createCriteria().andLike("username", username);
		}
		example.createCriteria().andEqualTo("deleted", 0);
		Page<NurseAdmin> result = PageHelper.startPage(page, limit);
		nurseAdminMapper.selectByExample(example);
		Map<String,Object> data = new HashMap<>();
		data.put("total", result.getTotal());
		data.put("items", result.getResult());
		return data;
	}

	public List<NurseAdmin> queryTotalSelective(String username, String sort, String order) {
		Example example = new Example(NurseAdmin.class);
		if (!StringUtils.isEmpty(username)) {
			example.createCriteria().andLike("username", username);
		}
		example.createCriteria().andEqualTo("deleted", 0);
		return nurseAdminMapper.selectByExample(example);
	}

	public List<NurseAdmin> findAdmin(String username) {
		Example example = new Example(NurseAdmin.class);
		example.createCriteria().andEqualTo("username", username).andEqualTo("deleted", 0);
		return nurseAdminMapper.selectByExample(example);
	}
}